package org.micode.demo.web.service;

import org.micode.demo.biz.vo.MenuVO;
import org.micode.demo.db.domain.dto.SysMenuDTO;
import org.micode.demo.db.service.DaoSysMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * 菜单信息的APP服务实现类
 *
 * author: wutianbin
 */
@Service
@Slf4j
public class MenuService {

    @Autowired
    private DaoSysMenuService daoSysMenuService;

    public List<SysMenuDTO> queryNotButtonList() {
        return daoSysMenuService.listMenuNotButtonByUser(null);
    }

    public MenuVO<SysMenuDTO> getUserNavigationMenus(Long userId) {
        List<SysMenuDTO> menuList = getUserMenuList(userId);
        Set<String> permissions = getUserPermissions(userId);
        MenuVO ret = new MenuVO<>(menuList, permissions);
        ret.setUserId(userId);
        return ret;
    }

    private Set<String> getUserPermissions(Long userId) {
        return daoSysMenuService.listPerms(userId);
    }

    private List<SysMenuDTO> getUserMenuList(Long userId) {
        return daoSysMenuService.listMenuByUser(userId);
    }

    public Integer update(SysMenuDTO sysMenu) {
        return daoSysMenuService.update(sysMenu);
    }

}
